﻿#if No_No_no_Error
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour
{

	public int currentPageIndex;

	public GameObject[] levelList;

	public int maxPage;

	public Text pageText;

	public int _mode;

	// Use this for initialization
	void Start ()
	{
		AdsControl.Instance.ShowBanner ();
		_mode = PlayerPrefs.GetInt ("Mode");
		currentPageIndex = 0;
		PlayerPrefs.SetInt ("Level" + _mode.ToString () + "1", 1);
		LoadLevelItem ();
	}
	
	// Update is called once per frame
	void Update ()
	{
		pageText.text = (currentPageIndex + 1).ToString () + "/" + maxPage.ToString ();
	}


	public void LoadLevelItem ()
	{
		for (int i = 1; i <= 10; i++) {

			levelList [i - 1].transform.Find ("Text").GetComponent<Text> ().text = (i + currentPageIndex * 10).ToString ();

			int _unLock = PlayerPrefs.GetInt ("Level" + _mode.ToString () + (i + currentPageIndex * 10));
			if (_unLock == 1)
				levelList [i - 1].GetComponent<Image> ().color = Color.white;
			else
				levelList [i - 1].GetComponent<Image> ().color = Color.cyan;
		}
	}

	public void NextPage ()
	{
		AudioManager.Instance.PlayClickSound ();
		if (currentPageIndex < maxPage - 1) {
			currentPageIndex++;
			LoadLevelItem ();
		}
	}

	public void PrePage ()
	{
		AudioManager.Instance.PlayClickSound ();
		if (currentPageIndex > 0) {
			currentPageIndex--;
			LoadLevelItem ();
		}
	}

	public void LoadLevel (int _index)
	{
		AudioManager.Instance.PlayClickSound ();
		int _unLock = PlayerPrefs.GetInt ("Level" + _mode.ToString () + (_index + currentPageIndex * 10));
		if (_unLock == 1) {
			PlayerPrefs.SetInt ("CurrentLevel", _index + currentPageIndex * 10);
			AdsControl.Instance.HideBanner ();
			//FireBaseManager.instance.LogScreen ("LEVEL_" + _mode.ToString () + "_" + (_index + currentPageIndex * 10).ToString ());
			SceneManager.LoadScene (1);

		}
	}
}
#endif